package me.jiatao.wan.ui.login

import android.widget.Toast
import androidx.databinding.ObservableBoolean
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onStart
import me.jiatao.wan.data.network.HttpConst
import me.jiatao.wan.data.network.doFailure
import me.jiatao.wan.data.network.doSuccess
import me.jiatao.wan.data.repository.Repository
import me.jiatao.wan.init.AppHelper
import javax.inject.Inject

/**
 * @Author: taojia
 * @CreateDate: 2021/9/8 4:10 下午
 * @Version: 1.0
 * @Description:
 */

@HiltViewModel
class UserViewModel @Inject constructor(
    private val repository: Repository
) : ViewModel() {

    /**
     * 加载状态
     */
    val loading = ObservableBoolean(false)

    /**
     * 用户登录
     */
    fun userLogin(userName: String, userPwd: String) =
        repository.postUserLogin(userName, userPwd)
            .onStart {
                loading.set(true)
            }
            .onCompletion {
                loading.set(false)
            }


}